package name.fowler.refactoring.simplestore;

import name.fowler.refactoring.simplestore.domain.Movie;
import name.fowler.refactoring.simplestore.domain.Rental;

public class BonusPointsCalculator extends Calculator {
	private int paramDays;
	private int paramBonusPoints;
	
	@Override
	public void calculateWhenPriceCodeChildren() {
		this.paramBonusPoints = 1;
	}

	@Override
	public void calculateWhenPriceCodeRegular() {
		this.paramBonusPoints = 1;
	}

	@Override
	public void calculateWhenPriceCodeNewRelease() {
		int days = this.paramDays;
        int bonusPoints = 1;
        if (days > 1) {
            bonusPoints += 1;
        }
        this.paramBonusPoints = bonusPoints;
	}

	public int getBonusPoints(Movie movie, int days)
	{
		this.paramBonusPoints = 0;
		this.paramDays = days;
		movie.getPriceCode().accept(this);
		return this.paramBonusPoints;
	}
	
	public int getBonusPoints(Rental rental)
	{
		int sum = 0;
		for (Movie movie : rental.getMovies()) {
			sum += this.getBonusPoints(movie, rental.getDaysRented());
		}
		return sum;
	}
}
